package com.example.module_parking.ui

import com.example.module_message.http.ParkingApi
import com.example.module_message.http.ParkingNetModule
import com.example.module_parking.model.AddParkingInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class ParkingRepository @Inject constructor() {
    @Inject
    @ParkingNetModule.CommonMainApi
    lateinit var parkingApi: ParkingApi

    /*
   获取停车场列表
    */
    fun getParkingList(spaceType:String) = flow {
        emit(parkingApi.getMessageList(spaceType))
    }.flowOn(Dispatchers.IO)

    fun addParking(addParkingInfo: AddParkingInfo) = flow {
        emit(parkingApi.addParking(addParkingInfo))
    }.flowOn(Dispatchers.IO)

    fun editParking(id:Int,addParkingInfo: AddParkingInfo) = flow {
        emit(parkingApi.editParking(id,addParkingInfo))
    }.flowOn(Dispatchers.IO)
    fun searchParking(id:Int) = flow {
        emit(parkingApi.searchParking(id))
    }.flowOn(Dispatchers.IO)
}